import {
	get,
	post
} from '../../utils/request.js'
Page({

  /**
   * 页面的初始数据
   */
  data: {
	  checked: true,
	  address: {},
	  listData: [],
	  allPrice: '',
	  info: '',
	  infonumber: 0,
	  totalNumber: 100
  },
  onLoad (options) {
	this.getStorageData()
  },
  onShow () {
	this.getDetail()
	this.getStorageData()
	
  },
  getStorageData() {
	  if (wx.getStorageSync('INFO')) {
	  	let info = wx.getStorageSync('INFO')
	  	let infonumber = wx.getStorageSync('INFONUMBER')
		// console.log(infonumber)
	 //  	console.log(info)
	  	this.setData({
	  		info: info,
	  		infonumber: infonumber,
	  		allPrice: info.retail_price * infonumber * 100,
	  		totalNumber: infonumber
	  	})
	  }
	  // console.log(this.data.totalNumber, 111)
  },
  toAddressList () {
	wx.navigateTo({
		url: '/pages/address/address'
	})
  },
  onChange () {
	  this.setData({
		  checked: !this.data.checked
	  })
  },
  async getDetail () {
	  const data = await get('/order/detailAction', {
		  openId: wx.getStorageSync('OPENID') || '',
		  addressId: wx.getStorageSync('addressId') || ''
	  })
	  // console.log(data)
	  this.setData({
		  address: data.address,
		  listData: data.goodsList
	  })
	  this.data.listData.map(item => {
		  this.setData({
			 allPrice: Number(item.retail_price * item.number * 100) + Number(this.data.allPrice), // 计算总价 
		  })
	  })
	  let arr = []
	  let sum = 0
	  this.data.listData.filter(item => {
		  arr.push(item.number)
	  })
	  //console.log(arr)
	  for (var i=0;i<arr.length;i++) {
		  sum += arr[i]
	  }
	  // console.log(sum)
	  this.setData({
		  totalNumber: sum
	  })
  },
  onSubmit () {
	wx.showModal({
		title: '操作提示',
		content: '支付功能暂未开发,是否需要返回首页?',
		success(res) {
			if (res.confirm) {
				wx.switchTab({
					url: '/pages/home/home'
				})
			}
		}
	}) 
  },
})